package org.geektimes.projects.user.web.controller;

import org.geektimes.projects.user.domain.User;
import org.geektimes.projects.user.repository.InMemoryUserRepository;
import org.geektimes.projects.user.repository.UserRepository;
import org.geektimes.web.mvc.controller.PageController;
import sun.plugin.util.UIUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.util.Map;
import java.util.UUID;

/**
 * @author: fengabner
 * @date: 2021/3/2 22:24
 * @version: 1.0
 * @description:
 */
@Path("/user")
public class UserController implements PageController {
    @POST
    @Path("/register")
    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws Throwable {
        System.out.println("hahahahhahahahah");
        String email = request.getParameter("email");
        String password = request.getParameter("password");
        User user = new User();
        user.setEmail(email);
        user.setPassword(password);
        UserRepository userRepository = new InMemoryUserRepository();
        if (userRepository.save(user)) {
            request.setAttribute("name", email);
            return "success.jsp";
        }
        request.setAttribute("errorInfo", "请不要重复注册");
        //request.getRequestDispatcher()
        return "error.jsp";
    }
}
